using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Terra.Core.Infrastructure.Email.Interfaces;
using Terra.Core.Infrastructure.Email.Options;
using Terra.Core.Infrastructure.Email.Services;
using Terra.Core.Infrastructure.SMS.Interfaces;
using Terra.Core.Infrastructure.SMS.Options;
using Terra.Core.Infrastructure.SMS.Services;

namespace Terra.Core.Infrastructure.Extensions;

/// <summary>
/// 服务注册扩展方法
/// </summary>
public static class ServiceCollectionExtensions
{
    /// <summary>
    /// 添加邮件服务
    /// </summary>
    public static IServiceCollection AddEmailService(
        this IServiceCollection services,
        IConfiguration configuration)
    {
        services.Configure<EmailOptions>(configuration.GetSection("Email"));
        services.AddScoped<IEmailSender, SmtpEmailSender>();
        return services;
    }

    /// <summary>
    /// 添加短信服务
    /// </summary>
    public static IServiceCollection AddSmsService(
        this IServiceCollection services,
        IConfiguration configuration)
    {
        services.Configure<SmsOptions>(configuration.GetSection("SMS"));
        services.AddHttpClient<ISmsSender, DefaultSmsSender>();
        return services;
    }
}